package com.jivam.lottery.model;

/**
 * 计算工具中产生的排列数
 * @author Jivam
 */
public class SelectNum {
	private int a;
	private int b;
	private int c;
	private int d;
	private int e;
	private int f;
	private int g;
	
	boolean haveA;
	boolean haveB;
	boolean haveC;
	boolean haveD;
	boolean haveE;
	boolean haveF;
	boolean haveG;
	
	private int empty4;
	private int sum4;
	
	private boolean double2;
	private boolean double3;
	private boolean double4;
	private boolean doubleall;
	
	private int abSum;
	private int acSum;
	private int adSum;
	private int aeSum;
	private int afSum;
	private int agSum;
	private int bcSum;
	private int bdSum;
	private int beSum;
	private int bfSum;
	private int bgSum;
	private int cdSum;
	private int ceSum;
	private int cfSum;
	private int cgSum;
	private int deSum;
	private int dfSum;
	private int dgSum;
	private int efSum;
	private int egSum;
	private int fgSum;
	
	private int abcSum;
	private int abdSum;
	private int acdSum;
	private int bcdSum;
	private int abcdSum;
	
	private int kuaduzhi = -1;
	private int a_b = -1;
	private int b_c = -1;
	private int a_c = -1;
	private int b_d = -1;
	private int a_d = -1;
	private int c_d = -1;
	
	private boolean duishu;
	private boolean xiongdishu;
	private boolean touweipei;
	
	public SelectNum(int a, int b, int c, int d, int e, int f, int g, int empty4, 
			boolean haveA,boolean haveB, boolean haveC, boolean haveD, boolean haveE, boolean haveF, boolean haveG) {
		super();
		this.a = a;
		this.b = b;
		this.c = c;
		this.d = d;
		this.e = e;
		this.f = f;
		this.g = g;
		this.empty4 = empty4;
		this.haveA = haveA;
		this.haveB = haveB;
		this.haveC = haveC;
		this.haveD = haveD;
		this.haveE = haveE;
		this.haveF = haveF;
		this.haveG = haveG;
		
		double4 = isDouble4();
		double3 = isDouble3C();
		double2 = isDouble2C();
		
		doubleall = double2 || double3 || double4;
		calculator();
		duishu = isDS();
		xiongdishu = isXDS();
		touweipei = isTWP();
	}
	

	
	private void calculator(){
		abSum = (a+b)%10;
		acSum = (a+c)%10;
		adSum = (a+d)%10;
		aeSum = (a+e)%10;
		afSum = (a+f)%10;
		agSum = (a+g)%10;
		bcSum = (b+c)%10;
		bdSum = (b+d)%10;
		beSum = (b+e)%10;
		bfSum = (b+f)%10;
		bgSum = (b+g)%10;
		cdSum = (c+d)%10;
		ceSum = (c+e)%10;
		cfSum = (c+f)%10;
		cgSum = (c+g)%10;
		deSum = (d+e)%10;
		dfSum = (d+f)%10;
		dgSum = (d+g)%10;
		efSum = (e+f)%10;
		egSum = (e+g)%10;
		fgSum = (f+g)%10;
		
		abcSum = (a+b+c)%10;
		abdSum = (a+b+d)%10;
		acdSum = (a+c+d)%10;
		bcdSum = (b+c+d)%10;
		
		sum4 = a+b+c+d;
		abcdSum = sum4%10;
		
		if(haveA && haveB)
			a_b = Math.abs(a - b);
		if(haveB && haveC)
			b_c = Math.abs(b - c);
		if(haveA && haveC)
			a_c = Math.abs(a - c);
		if(haveB && haveD)
			b_d = Math.abs(b - d);
		if(haveA && haveD)
			a_d = Math.abs(a - d);
		if(haveC && haveD)
			c_d = Math.abs(c - d);
		
		if(empty4 < 3){
			kuaduzhi = Math.max(a_b, b_c);
			kuaduzhi = Math.max(kuaduzhi, a_c);
			kuaduzhi = Math.max(kuaduzhi, b_d);
			kuaduzhi = Math.max(kuaduzhi, a_d);
			kuaduzhi = Math.max(kuaduzhi, c_d);
		}
	}
	
	/**
	 * 头尾不配
	 * 当0为头时不配5尾、1头不配8尾、2--1、3--4、4--7、5--0、6--3、7--6、8--9、9--2
	 * @return
	 */
	private boolean isTWP(){
		if(haveA && haveD){
			switch (a) {
			case 0: if(d == 5) return true;
			case 1: if(d == 8) return true;
			case 2: if(d == 1) return true;
			case 3: if(d == 4) return true;
			case 4: if(d == 7) return true;
			case 5: if(d == 0) return true;
			case 6: if(d == 3) return true;
			case 7: if(d == 6) return true;
			case 8: if(d == 9) return true;
			case 9: if(d == 2) return true;
			default: break;
			}
		}
		return false;
	}
	
	private boolean isXDS(){
		if(empty4 > 2)
			return false;
		if(a_b == 1 || b_c == 1 || a_c == 1 || b_d == 1 || a_d == 1 || c_d == 1)
			return true;
		
		return false;
	}
	
	private boolean isDS(){
		if(empty4 > 2)
			return false;
		if(a_b == 5 || b_c == 5 || a_c == 5 || b_d == 5 || a_d == 5 || c_d == 5)
			return true;
		
		return false;
	}
	
	private boolean isDouble2C(){
		if(empty4 > 2 || double3)
			return false;
		if(haveA && haveB && a == b)
			return true;
		if(haveB && haveC && b == c)
			return true;
		if(haveA && haveC && a == c)
			return true;
		if(haveB && haveD && b == d)
			return true;
		if(haveA && haveD && a == d)
			return true;
		if(haveC && haveD && c == d)
			return true;
		
		return false;
	}
	
	private boolean isDouble3C(){
		if(empty4 > 1)
			return false;
		if(haveA && haveB && haveC && a == b && b == c)
			return true;
		if(haveA && haveB && haveD && a == b && b == d)
			return true;
		if(haveA && haveC && haveD && a == c && c == d)
			return true;
		if(haveB && haveC && haveD && b == c && c == d)
			return true;
		
		return false;
	}
	
	private boolean isDouble4(){
		if(empty4 > 0)
			return false;
		if(a == b && b == c && c==d)
			return true;
		
		return false;
	}
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		if(haveE || haveF || haveG){
			sb.append(haveA?a:"X");
			sb.append(" ");
			sb.append(haveB?b:"X");
			sb.append(" ");
			sb.append(haveC?c:"X");
			sb.append(" ");
			sb.append(haveD?d:"X");
			sb.append(" ");
			sb.append(haveE?e:"X");
			sb.append(" ");
			sb.append(haveF?f:"X");
			sb.append(" ");
			sb.append(haveG?g:"X");
		}else{
			sb.append(haveA?a:"X");
			sb.append(haveB?b:"X");
			sb.append(haveC?c:"X");
			sb.append(haveD?d:"X");
		}
		return sb.toString();
	}

	public int getA() {
		return a;
	}

	public void setA(int a) {
		this.a = a;
	}

	public int getB() {
		return b;
	}

	public void setB(int b) {
		this.b = b;
	}

	public int getC() {
		return c;
	}

	public void setC(int c) {
		this.c = c;
	}

	public int getD() {
		return d;
	}

	public void setD(int d) {
		this.d = d;
	}

	public int getE() {
		return e;
	}

	public void setE(int e) {
		this.e = e;
	}

	public int getF() {
		return f;
	}

	public void setF(int f) {
		this.f = f;
	}

	public int getG() {
		return g;
	}

	public void setG(int g) {
		this.g = g;
	}

	public int getEmpty() {
		return empty4;
	}

	public void setEmpty(int empty) {
		this.empty4 = empty;
	}

	public boolean isHaveA() {
		return haveA;
	}

	public void setHaveA(boolean haveA) {
		this.haveA = haveA;
	}

	public boolean isHaveB() {
		return haveB;
	}

	public void setHaveB(boolean haveB) {
		this.haveB = haveB;
	}

	public boolean isHaveC() {
		return haveC;
	}

	public void setHaveC(boolean haveC) {
		this.haveC = haveC;
	}

	public boolean isHaveD() {
		return haveD;
	}

	public void setHaveD(boolean haveD) {
		this.haveD = haveD;
	}

	public boolean isHaveE() {
		return haveE;
	}

	public void setHaveE(boolean haveE) {
		this.haveE = haveE;
	}

	public boolean isHaveF() {
		return haveF;
	}

	public void setHaveF(boolean haveF) {
		this.haveF = haveF;
	}

	public boolean isHaveG() {
		return haveG;
	}

	public void setHaveG(boolean haveG) {
		this.haveG = haveG;
	}

	public int getSum4() {
		return sum4;
	}

	public void setSum4(int sum4) {
		this.sum4 = sum4;
	}

	public boolean isDouble2() {
		return double2;
	}

	public void setDouble2(boolean double2) {
		this.double2 = double2;
	}

	public boolean isDouble3() {
		return double3;
	}

	public void setDouble3(boolean double3) {
		this.double3 = double3;
	}

	public boolean isDoubleall() {
		return doubleall;
	}

	public void setDoubleall(boolean doubleall) {
		this.doubleall = doubleall;
	}

	public int getAbSum() {
		return abSum;
	}

	public void setAbSum(int abSum) {
		this.abSum = abSum;
	}

	public int getAcSum() {
		return acSum;
	}

	public void setAcSum(int acSum) {
		this.acSum = acSum;
	}

	public int getAdSum() {
		return adSum;
	}

	public void setAdSum(int adSum) {
		this.adSum = adSum;
	}

	public int getAeSum() {
		return aeSum;
	}

	public void setAeSum(int aeSum) {
		this.aeSum = aeSum;
	}

	public int getAfSum() {
		return afSum;
	}

	public void setAfSum(int afSum) {
		this.afSum = afSum;
	}

	public int getAgSum() {
		return agSum;
	}

	public void setAgSum(int agSum) {
		this.agSum = agSum;
	}

	public int getBcSum() {
		return bcSum;
	}

	public void setBcSum(int bcSum) {
		this.bcSum = bcSum;
	}

	public int getBdSum() {
		return bdSum;
	}

	public void setBdSum(int bdSum) {
		this.bdSum = bdSum;
	}

	public int getBeSum() {
		return beSum;
	}

	public void setBeSum(int beSum) {
		this.beSum = beSum;
	}

	public int getBfSum() {
		return bfSum;
	}

	public void setBfSum(int bfSum) {
		this.bfSum = bfSum;
	}

	public int getBgSum() {
		return bgSum;
	}

	public void setBgSum(int bgSum) {
		this.bgSum = bgSum;
	}

	public int getCdSum() {
		return cdSum;
	}

	public void setCdSum(int cdSum) {
		this.cdSum = cdSum;
	}

	public int getCeSum() {
		return ceSum;
	}

	public void setCeSum(int ceSum) {
		this.ceSum = ceSum;
	}

	public int getCfSum() {
		return cfSum;
	}

	public void setCfSum(int cfSum) {
		this.cfSum = cfSum;
	}

	public int getCgSum() {
		return cgSum;
	}

	public void setCgSum(int cgSum) {
		this.cgSum = cgSum;
	}

	public int getDeSum() {
		return deSum;
	}

	public void setDeSum(int deSum) {
		this.deSum = deSum;
	}

	public int getDfSum() {
		return dfSum;
	}

	public void setDfSum(int dfSum) {
		this.dfSum = dfSum;
	}

	public int getDgSum() {
		return dgSum;
	}

	public void setDgSum(int dgSum) {
		this.dgSum = dgSum;
	}

	public int getEfSum() {
		return efSum;
	}

	public void setEfSum(int efSum) {
		this.efSum = efSum;
	}

	public int getEgSum() {
		return egSum;
	}

	public void setEgSum(int egSum) {
		this.egSum = egSum;
	}

	public int getFgSum() {
		return fgSum;
	}

	public void setFgSum(int fgSum) {
		this.fgSum = fgSum;
	}

	public int getAbcSum() {
		return abcSum;
	}

	public void setAbcSum(int abcSum) {
		this.abcSum = abcSum;
	}

	public int getAbdSum() {
		return abdSum;
	}

	public void setAbdSum(int abdSum) {
		this.abdSum = abdSum;
	}

	public int getAcdSum() {
		return acdSum;
	}

	public void setAcdSum(int acdSum) {
		this.acdSum = acdSum;
	}

	public int getBcdSum() {
		return bcdSum;
	}

	public void setBcdSum(int bcdSum) {
		this.bcdSum = bcdSum;
	}

	public int getAbcdSum() {
		return abcdSum;
	}

	public void setAbcdSum(int abcdSum) {
		this.abcdSum = abcdSum;
	}

	public int getKuaduzhi() {
		return kuaduzhi;
	}

	public void setKuaduzhi(int kuaduzhi) {
		this.kuaduzhi = kuaduzhi;
	}

	public boolean isDuishu() {
		return duishu;
	}

	public void setDuishu(boolean duishu) {
		this.duishu = duishu;
	}

	public boolean isXiongdishu() {
		return xiongdishu;
	}

	public void setXiongdishu(boolean xiongdishu) {
		this.xiongdishu = xiongdishu;
	}

	public boolean isTouweipei() {
		return touweipei;
	}

	public void setTouweipei(boolean touweipei) {
		this.touweipei = touweipei;
	}

	public void setDouble4(boolean double4) {
		this.double4 = double4;
	}



	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + a;
		result = prime * result + b;
		result = prime * result + c;
		result = prime * result + d;
		result = prime * result + e;
		result = prime * result + f;
		result = prime * result + g;
		result = prime * result + (haveA ? 1231 : 1237);
		result = prime * result + (haveB ? 1231 : 1237);
		result = prime * result + (haveC ? 1231 : 1237);
		result = prime * result + (haveD ? 1231 : 1237);
		result = prime * result + (haveE ? 1231 : 1237);
		result = prime * result + (haveF ? 1231 : 1237);
		result = prime * result + (haveG ? 1231 : 1237);
		return result;
	}



	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		SelectNum other = (SelectNum) obj;
		if (a != other.a)
			return false;
		if (b != other.b)
			return false;
		if (c != other.c)
			return false;
		if (d != other.d)
			return false;
		if (e != other.e)
			return false;
		if (f != other.f)
			return false;
		if (g != other.g)
			return false;
		if (haveA != other.haveA)
			return false;
		if (haveB != other.haveB)
			return false;
		if (haveC != other.haveC)
			return false;
		if (haveD != other.haveD)
			return false;
		if (haveE != other.haveE)
			return false;
		if (haveF != other.haveF)
			return false;
		if (haveG != other.haveG)
			return false;
		return true;
	}

	
	
	
}
